home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / MATHASM.LZH / ASC32.ASM < prev    next >
Assembly Source File  |  1985-12-03  |  3KB  |  54 lines

  1. ASC32    PROC     NEAR
  2. ;***************************************************************
  3. ;                    Converts a 32-bit signed integer to ASCII
  4. ;                    SI points to integer; DI to ASCII last byte
  5. ;                    in ASCII location. BX returns offset to 
  6. ;                    first character (sign)
  7. ;****************************************************************
  8.          PUSH     SI
  9.          PUSH     DI
  10.          SUB      DX,DX           ;clear DX & BX
  11.          MOV      BX,DX
  12.          MOV      AX,[SI]         ;get integer
  13.          OR       DX,[SI]+2
  14. ;                            check sign
  15.          MOV      SI," "          ;assume positive sign
  16.          JNS      ASC32A          ;if number negative
  17.          NOT      AX              ;make it positive
  18.          NOT      DX
  19.          ADD      AX,1
  20.          ADC      DX,0
  21.          MOV      SI,"-"          ;and set negative sign
  22. ;
  23. ASC32A:  PUSH     SI              ;save sign
  24. ;                            break into two 3-4 digit integers
  25.          MOV      BX,10000        ;decimal 10,000 in BX
  26.          DIV      BX              ;divide integer by 10,000
  27. ;
  28.          PUSH     AX              ;quotient--first 3 ASCII digits
  29.          MOV      SI,OFFSET IM1   ;SI points to positive integer 
  30.          MOV      IM1,DX          ;remainder in range 0-9,999
  31.          CALL     ASC16           ;convert remainder to ASCII
  32. ;                            check for zero quotient
  33.          POP      AX              ;get the quotient
  34.          OR       AX,AX
  35.          JZ       ASC32D          ;finished if it is zero
  36. ;                            adjust ASCII remainder
  37.          MOV      CX,BX           ;pointer to ASCII sign in CX
  38.          SUB      CX,DI           ;CX is count of ASCII digits
  39.          ADD      CX,4            ;should be 4
  40.          JZ       ASC32C          ;if it isn't
  41. ASC32B:  MOV BYTE PTR [BX],"0"    ;fill it out with zeros
  42.          DEC      BX
  43.          LOOP     ASC32B
  44. ;                            convert quotient
  45. ASC32C:  MOV      DI,BX           ;DI points to next position
  46.          MOV      SI,OFFSET IM1   ;SI points to location of
  47.          MOV      IM1,AX          ;quotient in memory
  48.          CALL     ASC16           ;convert it
  49. ;                            set ASCII sign
  50. ASC32D:  POP      SI              ;get sign
  51.          MOV      AX,SI           ;put it in AL
  52.          MOV      [BX],AL         ;and save it
  53.          JMP      EXIT
  54. ASC32    ENDP